﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using phpmk.ADM.Out;
using phpmk.ADM.Core.Configuration;

namespace phpmk.ADM.Commands.Test
{
    class TestCommand : ICommand
    {
        public void Execute(System.Collections.Specialized.StringDictionary parameters)
        {
            bool inTestMode = true;
            if (parameters.ContainsKey("target")) {
                Boolean.TryParse(parameters["target"], out inTestMode);
            } else if (parameters.ContainsKey("disable") || parameters.ContainsKey("false"))  {
                inTestMode = false;
            }

            ConfigFile.GetInstance().Model.runInTestMode = inTestMode;
            Output.GetInstance().Info("Test Mode : " + (inTestMode ? "ENABLED" : "DISABLED"));
        }

        public void Help()
        {
            Output output = Output.GetInstance();
            output.Info("You can use the -test command to test out what a certain command or chain of commands will do, or how will it behave when building based on the configuration file." + 
                        "\n\nIf no parameter is defined, just including -test command will assume test mode is enabled");
            output.Write("\nUsage Info: phpmk -test [-command [/arg] [--plugin [/opt]]");
            output.Write("\nParameters (Optional):");
            output.StartTable(2);
            output.AddRow(new string[] { " /enable", "Enables test mode" });
            output.AddRow(new string[] { " /true", "Enables test mode" });
            output.AddRow(new string[] { " /disable", "Disables test mode" });
            output.AddRow(new string[] { " /false", "Disables test mode" });
            output.EndTable();

        }

        public string Info()
        {
            return "Executes a buid/deploy test based on the configuration file";
        }
    }
}
